package com.ssy.controller;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.CircleCaptcha;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;

/**
 * CheckCode
 *
 * @author ssy
 * @date 2020/11/12
 **/
@WebServlet(urlPatterns = {"/CheckCode.do"})
public class CheckCodeServlet extends HttpServlet implements Serializable {
    private static final long serialVersionUID = 3539139320589722605L;

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        CircleCaptcha checkCode = CaptchaUtil.createCircleCaptcha(200, 100,4,50);
        String code = checkCode.getCode();
        System.out.println(code);
        req.getSession().setAttribute("code", code);
        checkCode.write(resp.getOutputStream());//输出到页面
    }
}
